import React, { Component } from 'react';
import DetailView from './DetailData/DetailView'
import detailHttp from '../../api/detail'
import commentHttp from '../../api/comment'
class Detail extends Component {
    constructor(props){
        super(props)
        this.state = {
            detailData:null,
            commentData:[]
        }
    }
    componentDidMount(){
        let id = this.props.match.params.id;
        commentHttp.commentData(id).then(data=>{
            this.setState({
                commentData:data.data
            })
        })
        detailHttp.getDetail(id).then(data=>{
            this.setState({
                detailData:data
            })
        })
    }
    render() {
        return (
            <div>
               {
                   this.state.detailData?<DetailView data={this.state.detailData} comments={this.state.commentData} id={this.props.match.params.id}/>:<div>数据加载中...</div>
               }
            </div>
        );
    }
}

export default Detail;